import ACCESS_ENUM from "./ACCESS_ENUM";
// 判断用户有什么权限,如果没传入needAccess默认未登录
const checkAccess = (userRole: any, needAccess = ACCESS_ENUM.NOT_LOGIN) => {
  // 获取当前用户具有什么权限(没有找到，默认未登录)
  const loginUserAccess = userRole ?? ACCESS_ENUM.NOT_LOGIN;
  if (needAccess === ACCESS_ENUM.NOT_LOGIN) {
    return true;
  }
  if (needAccess === ACCESS_ENUM.USER) {
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
  }
  if (needAccess === ACCESS_ENUM.ADMIN) {
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
    if (loginUserAccess === ACCESS_ENUM.USER) {
      return false;
    }
  }
  return true;
};

export default checkAccess;
